<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>添加活动计划</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>CSS/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>JS/jquery-ui-1.11.2/jquery-ui.css">
	<script type="text/javascript" src="<%=basePath%>JS/jquery-ui-1.11.2/external/jquery/jquery.js"></script>
	<script type="text/javascript" src="<%=basePath%>JS/jquery-ui-1.11.2/jquery-ui.js"></script>
	<script type="text/javascript" src="<%=basePath%>JS/WongDatePicker.js"></script>
  </head>
  
  <body>
      	<div id="head-search">
   	 		<i class="home-path"></i>
   	 		<span class="path-font">活动管理 &nbsp;&nbsp;>>&nbsp;&nbsp;添加活动计划</span>
   		</div>
   		<div class="mainbody">
   			<div class="mainleft">
   				<div id="activiylists" >
   					<div class="activityplan-list">年份：<select id="year" style="width:100px"></select></div>
   					<div class="activityplan-list">学期：<select id="semester" style="width:100px"><option>1</option><option>2</option></select></div>
  					<div class="activityplan-list">备注：<input name="theme" id="theme"></div>
  				</div>
  				<div class="add-activityplan">
  					<button id="saveActivityBtn" class="wong-button-text-ui wong-button-blue">
   						<span class="wong-ui-icon wong-icon-save"></span>
   						<span >保存</span>
   					</button>
  					<button id="addActivityBtn" class="wong-button-text-ui wong-button-blue">
   						<span class="wong-ui-icon wong-icon-add"></span>
   						<span >增加活动</span>
   					</button>
   					<button id="saveActBtn" class="wong-button-text-ui wong-button-gray" disabled="disabled">
   						<span class="wong-ui-icon wong-icon-save"></span>
   						<span >保存活动</span>
   					</button>
   					<button id="finishBtn" class="wong-button-text-ui wong-button-gray" disabled="disabled" onclick="javascipt:window.location.href='activities/activityPlan.jsp';">
   						<span class="wong-ui-icon wong-icon-save"></span>
   						<span >完成</span>
   					</button>
   			</div>
   			<div id="activitiesList"></div>
   		</div>	
		
   		</div>
  </body>
  <script>
  		var activitynumber = 0;
  		var listid="";
  		$(function(){
  			
  			//年份选择
  			var date = new Date();
			var cur_year = date.getFullYear();
			var i=0;
			for(;i<5;i++){
				var tag = document.createElement("option");
				var a = document.createTextNode((cur_year-1+i)+"-"+(cur_year+i));
				tag.appendChild(a);
				var y = document.getElementById("year");
				y.appendChild(tag);		
			}
			
  			//隐藏活动相关按
 			$("#addActivityBtn").hide();
  			//$("#deleteActivityBtn").hide();
  			$("#saveActBtn").hide();
  			$("#finishBtn").hide();
  			
  			$("#saveActivityBtn").click(function(){
  				if(validatenull($("#theme"),"请添加备注说明")) return ; //判断是否为空
  				var yearstring=$('#year').val();	
  				var semesterString=$('#semester').val();
  				var themestring = $('#theme').val();
				//转换数据
  				var datas={'year':yearstring,'semester':semesterString,'theme':themestring};
  				
  				$.ajax({
  					url:'<%=basePath%>addListActivityAction',
  					type:'post',
  					typeData:'json',
  					data:datas,
  					timeout:1000,
  					async: false,
  					beforeSend:LoadFunction,
  					error:errFunction,
  					success:succFunction			
  				}); 
  				if(listid==0){
					return;
				}
  				$("#activiylists").html("<div class='divrow'>年份："+yearstring+"</div><div class='divrow'>学期："+semesterString+"</div><div class='divrow'>备注："+themestring+"</div>");
  				
  			});
  			

  			//添加活动按钮，点击添加活动相关标签
  			$("#addActivityBtn").click(function(){
  				activitynumber++;
  				$("#activitiesList").html(
  						"<div class='activities-list' id='activity"+activitynumber+"'>活动"+activitynumber+
  						":<span class='span'>活动时间：<input name='' id='actTime"+activitynumber+"' onfocus=\"setmonth(this,'yyyy-MM','2010-01','2050-12',1)\" readonly='readonly'/></span>"+
  						"<span class='span'>活动主题：<input name='' id='actTheme"+activitynumber+"'/></span>"+
  						"<span class='span'>活动地点：<input name='' id='actAddr"+activitynumber+"'/></span></div");
  				//$("#activity"+activitynumber).appendChild($("#saveActBtn"));
				//var a = document.getElementById("activityesList");
				//a.appendChild(document.getElementById("savaActBtn"));
				$("#addActivityBtn").attr("disabled","true");
				$("#addActivityBtn").removeClass("wong-button-blue");
				$("#addActivityBtn").addClass("wong-button-gray");
				$("#finishBtn").attr("disabled","true");
				$("#finishBtn").removeClass("wong-button-blue");
				$("#finishBtn").addClass("wong-button-gray");
				$("#saveActBtn").attr("disabled",false);
				$("#saveActBtn").addClass("wong-button-blue");
				$("#saveActBtn").removeClass("wong-button-gray");
  			});
  			
  			//删除活动按钮，点击删除活动相关标签
  			$("#deleteActivityBtn").click(function(){
  				$("#activity"+activitynumber).remove();
  				if(activitynumber>0)
  					activitynumber--;
  				if(activitynumber==0){
  					$("#addActivityBtn").attr("disabled",false);
  					$("#addActivityBtn").addClass("wong-button-blue");
  					$("#addActivityBtn").removeClass("wong-button-gray");
  				}
  			});
  			
  			//保存活动按钮，点击保存当前活动
  			$("#saveActBtn").click(function(){
  				//验证
  				if(validatenull($("#actTime"+activitynumber),"请选择活动举行日期")) return;
  				if(validatenull($("#actTheme"+activitynumber),"请输入活动主题")) return;
  				if(validatenull($("#actAddr"+activitynumber),"请输入活动举行地址")) return;
  				
  				var datess=$("#actTime"+activitynumber).val(),
  					themess=$("#actTheme"+activitynumber).val(),
  					addrss=$("#actAddr"+activitynumber).val();
  				
  				var activities = {"listID":listid,"date":datess,"theme":themess,"addr":addrss};
  				$.ajax({
  					url:'<%=basePath%>addPlanActivityAction',
  					type:'post',
  					typeData:'json',
  					data:activities,
  					timeout:1000,
  					async: false,
  					beforeSend:LoadFunction,
  					error:errFunction,
  					success:succ
  				});
  				$("#addActivityBtn").attr("disabled",false);
  				$("#addActivityBtn").addClass("wong-button-blue");
				$("#addActivityBtn").removeClass("wong-button-gray");
  				$("#finishBtn").attr("disabled",false);
				$("#finishBtn").addClass("wong-button-blue");
				$("#finishBtn").removeClass("wong-button-gray");
				$("#saveActBtn").attr("disabled",true);
				$("#saveActBtn").removeClass("wong-button-blue");
				$("#saveActBtn").addClass("wong-button-gray");
				$("#activiylists").html($("#activiylists").html()+"<div class='divrow'><span class='span'>活动"+activitynumber+"</span><span class='span'>主题："+themess+"</span><span class='span'>地点："+addrss+"</span><span class='span'>时间："+datess+"</span></div>");
				$("#activitiesList").html("");
  			});
  			
  		});
  			function LoadFunction(){}
			function errFunction(){}
			//添加活动列表成功后函数
			function succFunction(result){
					listid=eval("("+result+")").ids;//为什么加个括号就可以呢？
					if(listid==0){
						alert("当前学期计划活动已经添加，请于“查看计划活动”处查看");
						return;
					}
					$("#year").attr("disabled","true");
					$("#semester").attr("disabled","true");
					$("#theme").attr("disabled","true");
					$("#saveActivityBtn").hide();
					//$("#deleteActivityBtn").show();
					$("#addActivityBtn").show();
					$("#saveActBtn").show();
					$("#finishBtn").show();
				}
			
			function succ(){				
			}
			//验证表单是否为空,为空返回真
			function validatenull(value,tip){
				if(value.val()==undefined || value.val()==null || value.val()==""){
  					alert(tip);
  					value.focus();
  					return true;
  				}else{
  					return false;
  				}
  					
			}
  </script>
</html>
